class Solution {
public:
    vector<int> largestValues(TreeNode* root)
    {
        int len = INT_MIN;
        vector<int> ret;
        if (root == nullptr) return ret;
        queue<TreeNode*> q1;
        q1.push(root);
        while (q1.size())
        {
            int sz = q1.size();
            for (int i = 0; i < sz; i++)
            {
                auto front = q1.front();
                len = max(len, front->val);
                q1.pop();
                if (front->left)
                    q1.push(front->left);
                if (front->right)
                    q1.push(front->right);
            }
            ret.push_back(len);
            len = INT_MIN;
        }
        return ret;
    }
};